import * as Cesium from 'cesium';
//@ts-ignore
const { Model3DTileContent, Model, combine, Pass } = Cesium;
export default function fixModel3DTileContent() {
    Model3DTileContent.fromGltf = async function (tileset: any, tile: any, resource: any, gltf: any) {
        const content = new Model3DTileContent(tileset, tile, resource);

        const additionalOptions = {
            gltf: gltf,
            basePath: resource,
        };

        const modelOptions = makeModelOptions(
            tileset,
            tile,
            content,
            additionalOptions,
        );

        const classificationType = tileset.vectorClassificationOnly
            ? undefined
            : tileset.classificationType;

        modelOptions.classificationType = classificationType;

        const model = await Model.fromGltfAsync(modelOptions);
        content._model = model;

        return content;
    };
    function makeModelOptions(tileset: any, tile: any, content: any, additionalOptions: any) {
        const mainOptions = {
            cull: false, // The model is already culled by 3D Tiles
            releaseGltfJson: true, // Models are unique and will not benefit from caching so save memory
            opaquePass: Pass.CESIUM_3D_TILE, // Draw opaque portions of the model during the 3D Tiles pass
            modelMatrix: tile.computedTransform,
            upAxis: tileset._modelUpAxis,
            forwardAxis: tileset._modelForwardAxis,
            incrementallyLoadTextures: false,
            customShader: tileset.customShader,
            content: content,
            colorBlendMode: tileset.colorBlendMode,
            colorBlendAmount: tileset.colorBlendAmount,
            lightColor: tileset.lightColor,
            imageBasedLighting: tileset.imageBasedLighting,
            featureIdLabel: tileset.featureIdLabel,
            instanceFeatureIdLabel: tileset.instanceFeatureIdLabel,
            pointCloudShading: tileset.pointCloudShading,
            clippingPlanes: tileset.clippingPlanes,
            backFaceCulling: tileset.backFaceCulling,
            shadows: tileset.shadows,
            showCreditsOnScreen: tileset.showCreditsOnScreen,
            splitDirection: tileset.splitDirection,
            enableDebugWireframe: tileset._enableDebugWireframe,
            debugWireframe: tileset.debugWireframe,
            projectTo2D: tileset._projectTo2D,
            enablePick: tileset._enablePick,
            enableShowOutline: tileset._enableShowOutline,
            showOutline: tileset.showOutline,
            outlineColor: tileset.outlineColor,
            showGaussianSplatting: tileset.showGaussianSplatting,
        };

        return combine(additionalOptions, mainOptions);
    }
}